package com.youdianda.controller.user;


import com.youdianda.dto.ArticlePageQueryByCateIdDTO;
import com.youdianda.dto.ArticlePageQueryDTO;
import com.youdianda.dto.UserDTO;
import com.youdianda.result.Result;
import com.youdianda.service.NewArticlesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/index")
@Slf4j
public class IndexController {
    @Autowired
    private NewArticlesService newArticlesService;


    /**
     * 网页前端：最近更新
     * @param dto
     * @return
     */
    @GetMapping("/new")
    public Result getArticlePage(ArticlePageQueryDTO dto){
        return newArticlesService.getArticlePage(dto);
    }


    /**
     *  根据分类ID分页文章
     * @return
     */
    @GetMapping("/list")
    public Result getArticlePageByCateid(ArticlePageQueryByCateIdDTO dto){
        return newArticlesService.getArticlePageByCateid(dto);
    }


    /**
     * 主页所有基础模块
     * @return
     */
    @GetMapping("/index")
    public Result indexAll(){
        return newArticlesService.indexAll();
    }

    /**
     * 最新文章
     * @return
     */
    @GetMapping("/hot")
    public Result getNewArticle(){
        return newArticlesService.getNewArticle();
    }

    /**
     * 推荐文章
     * @return
     */
    @GetMapping("/recommend")
    public Result getrecommendArticle(){
        return newArticlesService.getrecommendArticle();
    }

    /**
     * 文章详情数据
     * @return
     */
    @GetMapping("/show")
    public Result showArticles(Integer id){
        return newArticlesService.showArticles(id);
    }

    /**
     * 注册
     * @return
     */
    @PostMapping("/reg")
    public Result reg(@RequestBody UserDTO dto){
        return newArticlesService.reg(dto);
    }

}
